layui.use(['form',"fsConfig","fsCommon"], function(){
    var form = layui.form,
        layer = layui.layer,
        fsCommon = layui.fsCommon,
        fsConfig = layui.fsConfig,
        jumpLogin = $.result(fsConfig, "filters.401");

    var token = localStorage.getItem('cdce_serivce_token');
    if (token === "") {
        jumpLogin()
    }

    //自定义验证规则
    form.verify({
        pwd: [
            /^[\S]{6,12}$/
            ,'密码必须6到12位，且不能出现空格'
        ]
        ,confrim_password: function(value){
            var pwd = $("input[name='new_passwd']").val();
            if(pwd !== value) {
                return '两次输入的密码不一致';
            }
        }
    });

    function callback(data){
        layer.msg("密码修改成功")
        localStorage.setItem('cdce_serivce_token',"")
        jumpLogin()
    }
    //监听提交
    form.on('submit(submit)', function(data){
        form_field = data;
        delete data.field.confrim_password;
        fsCommon.post('/desc/v1alpha/passwd/set',data.field,callback);
        return false;
    });

});